<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>注册 | 漫迷客</title>
<link rel="stylesheet" href="static/css/css.css">
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/all.min.css">
<link rel="stylesheet" href="static/css/styles1.css">
<link rel="stylesheet" href="static/css/color-switcher.min.css">
<link rel="stylesheet" href="static/css/preloader.min.css">
	<link rel="stylesheet" href="static/css/QVerify.min.css">
			<link rel="stylesheet" href="static/css/xiaoxi.css">
</head>
<body>

<div id="preloader-wrapper">
<div id="loading-layer">
<div class="loading">
<div class="rect-one"></div>
<div class="rect-two"></div>
<div class="rect-three"></div>
<div class="rect-four"></div>
<div class="rect-five"></div>
</div>
</div>
</div>


<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true); 
#获取用户注册的账号信息
$email=$_GET["mail"];
$name=$_GET["username"];
$password=$_GET["password"];
#判断codetime 是否存在 30秒内只能发送一次邮件 可以自己定义时间
if(isset($_SESSION['codetime'])){
    $now=time();
    $res=$now-intval($_SESSION['codetime']);
    
}else{
    $res=30;
}

if($res>=30){
      #随机生成验证码
$code=rand(1000,9999);
#$_SESSION['code']=$code;
##请在此处将网址内容 更改为你当前服务器的模板所在的网址
$huizhi=file_get_contents('http://localhost/email-master/muban.php?code='.$code);

$huizhi2="站长，".$name."注册了您的Madmic账号";
                             // Passing `true` enables exceptions
try {
    //服务器配置
    $mail->CharSet ="UTF-8";                     //设定邮件编码
    $mail->SMTPDebug = 0;                        // 调试模式输出
    $mail->isSMTP();                             // 使用SMTP
    $mail->Host = 'smtp.qq.com';                // SMTP服务器
    $mail->SMTPAuth = true;                      // 允许 SMTP 认证
    $mail->Username = 'xxxxxxxx@qq.com';                // SMTP 用户名  即邮箱的用户名
    $mail->Password = 'xxxxxxxxxxxxxxxxx';             // SMTP 密码  部分邮箱是授权码(例如163邮箱)
    $mail->SMTPSecure = 'ssl';                    // 允许 TLS 或者ssl协议
    $mail->Port = 465;                            // 服务器端口 25 或者465 具体要看邮箱服务器支持

    $mail->setFrom('xxxxxxxx@qq.com', 'chenkk');  //发件人
    $mail->addAddress($email,$name);  // 收件人
    //$mail->addAddress('ellen@example.com');  // 可添加多个收件人
    $mail->addReplyTo('xxxxxxxx@qq.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致
    //$mail->addCC('cc@example.com');                    //抄送
    //$mail->addBCC('bcc@example.com');                    //密送

    //发送附件
    // $mail->addAttachment('../xy.zip');         // 添加附件
    // $mail->addAttachment('../thumb-1.jpg', 'new.jpg');    // 发送附件并且重命名

    //Content
    $mail->isHTML(true);                                  // 是否以HTML文档格式发送  发送后客户端可直接显示对应HTML内容
    $mail->Subject = '欢迎注册陈盔盔网站会员！';
    $mail->Body    = $huizhi;
    $mail->AltBody = '你的设备不支持此邮件，请使用谷歌浏览器查看！';

    $mail->send();
    echo '邮件发送成功！请按邮件提示进行激活！<a href="login6.html">返回登陆页</a>';
} catch (Exception $e) {
    echo '邮件发送失败: ', $mail->ErrorInfo;
}
$mail2 = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //服务器配置
    $mail2->CharSet ="UTF-8";                     //设定邮件编码
    $mail2->SMTPDebug = 0;                        // 调试模式输出
    $mail2->isSMTP();                             // 使用SMTP
    $mail2->Host = 'smtp.qq.com';                // SMTP服务器
    $mail2->SMTPAuth = true;                      // 允许 SMTP 认证
    $mail2->Username = 'xxxxxxxx@qq.com';                // SMTP 用户名  即邮箱的用户名
    $mail2->Password = 'xxxxxxxxxxxxxxxxx';             // SMTP 密码  部分邮箱是授权码(例如163邮箱)
    $mail2->SMTPSecure = 'ssl';                    // 允许 TLS 或者ssl协议
    $mail2->Port = 465;                            // 服务器端口 25 或者465 具体要看邮箱服务器支持

    $mail2->setFrom('xxxxxxxx@qq.com', 'chenkk');  //发件人
    $mail2->addAddress('xxxxxxxx@qq.com','站长');  // 收件人
    //$mail->addAddress('ellen@example.com');  // 可添加多个收件人
    $mail2->addReplyTo('xxxxxxxx@qq.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致
    //$mail->addCC('cc@example.com');                    //抄送
    //$mail->addBCC('bcc@example.com');                    //密送

    //发送附件
    // $mail->addAttachment('../xy.zip');         // 添加附件
    // $mail->addAttachment('../thumb-1.jpg', 'new.jpg');    // 发送附件并且重命名

    //Content
    $mail2->isHTML(true);                                  // 是否以HTML文档格式发送  发送后客户端可直接显示对应HTML内容
    $mail2->Subject = $huizhi2;
    $mail2->Body    = $huizhi2;
    $mail2->AltBody = '你的设备不支持此邮件，请使用谷歌浏览器查看！';

    $mail2->send();
    $_SESSION['codetime']=time();
    //echo '邮件发送成功！请按邮件提示进行激活！<a href="login6.html">返回登陆页</a>';
} catch (Exception $e) {
    echo '邮件发送失败: ', $mail2->ErrorInfo;
}  
}

?>


<div class="d-flex justify-content-center swish-wrapper text-center" id="auth-page">
<div class="container-fluid form-container shadow rounded my-auto">
<div class="row h-100">

<div class="col-md-7 form-box bg-white rounded-left">
<div class="d-flex flex-column sign-in-container h-100">
<div class="align-items-center sign-in mx-auto my-auto px-4">


<div class="py-3">
<a class="logo-link" href="login6.html">
<img class="logo-image" alt="Logo" src="static/picture/logo.png">
</a>
</div>
<h3 class="text-neutral font-weight-bold py-1" style="font-size: 24px;">我们已经给您的邮箱发送了验证码</h3>
<p class="text-main">没有收到邮件?请等待30秒再次发送！</p>

<!-- form 提交给后台 验证 验证码 是否正确 -->
<form class="sign-in-form box-rounded" method="get" action="yanzheng.php">
<div class="form-group mt-3">
<input class="form-control form-control-lg box-rounded" type="text" id="username" placeholder="用户名" value="<?php echo $name; ?>" name="username" required="">
</div>
<div class="form-group mt-2">
<input class="form-control form-control-lg box-rounded" type="email" id="mail" placeholder="邮箱" value="<?php echo $email; ?>" name="mail" required="">
</div>
<div class="form-group">
<input class="form-control form-control-lg box-rounded" type="password" id="password" required="" name="code" placeholder="验证码">
</div>

<div class="form-row text-nowrap d-flex my-4">
<div class="col d-flex align-items-center">
<div class="form-check">
<a class="text-neutral font-weight-bold" href="login6.html">已经有账号了？点击登录</a>
</div>
</div>

</div>

<div class="d-flex">
<button class="btn btn-main mr-4 col shadow-sm box-rounded text-600" id="fasong" type="button" onClick="window.location.reload();">等待30秒</button>
<button class="btn btn-main mr-4 col shadow-sm box-rounded text-600" id="fasong" type="submit" >注册</button>
</div>
</form>

</div>
</div>
</div>


<div class="col-md-5 overlay-box bg-white rounded-right d-none d-md-block">
<div class="overlay-background mx-auto rounded-right" ></div>
</div>

</div>
</div>
</div>
<script>
var secs = 30;
 document.getElementById("fasong").disabled=true;
for(var i=1;i<=secs;i++) {
window.setTimeout("update(" + i + ")", i * 1000);
}
function update(num) {
//http://www.javaweb.cc整理
if(num == secs) {
document.getElementById("fasong").innerHTML ="重新发送";
document.getElementById("fasong").disabled=false;
}
else {
var printnr = secs-num;
document.getElementById("fasong").innerHTML = "等待" + printnr +"秒";
}
}
</script>

<script src="static/js/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/color-switcher.min.js"></script>
<script src="static/js/preloader.min.js"></script>
</body>
</html>
